Remove the model property from Factories and add extends annotation #128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
$model
property is not needed anymore starting from Laravel 8 laravel/framework#39310, as the Factory can find the name of the Model to create in other ways.In Laravel 9, however, they made the factories generic laravel/framework#39169. It allows for much better static analysis and autocompletion in tests.
This PR adds a new rule to the Laravel 8.0 set that removes the
$model
property from all factories and adds the@extends
annotation to the Factory with the removed$model
value. Users can only reap the benefits of the annotation starting from Laravel 9.0.The reason I did not add an extra rule to add the annotation separately is that we don't have a way to correctly determine the name of the model to use. We can add the annotation safely only if we get it from the user-defined
$model
value.Update
Removing the
$model
property actually works only if the Models are in theApp\Models
orApp
namespace, so removing them by default doesn't make much sense. I will make two separate rules in this case:$model
property, outside of any set list.@extends
annotation if there is a$model
property defined, which will be part of the Laravel 9 set list.